/**
 * Anonymous self-executing object for the configuration/testing Interface of Module Database
 */
(function() {

	$('#module-database-control form').ajaxForm({
		data: {
			cmd: "Update_Alias",
			alias: $('#module-database-control').data('alias')
		},
		success: function(r) {
			alert("Update done.");
		}
	});
	
	$('#db-test-connection').click(function() {
		$.post('/control', {
			cmd: "Module_Command",
			alias: $('#module-database-control').data('alias'),
			moduleCmd: "TestConnection"
		}, function(r) {
			var	dialog_title = "Connection test",
				dialog_html = r?
				'<div class="ui-state-highlight" style="padding: 0.2em 0.8em;"><p><span class="ui-icon ui-icon-info" style="float:left; margin:0 7px 50px 0;"></span>Connection successful.</p></div>':
				'<div class="ui-state-error" style="padding: 0.2em 0.8em;"><p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 50px 0;"></span><b>Warning</b>, failed to connect !</p></div>';
			
			$("<div>"+dialog_html+"</div>")
			.dialog({
				modal: true,
				resizable: false,
				title: dialog_title,
				width: 250,
				buttons: {
					"Ok": function() {
						$(this).dialog("destroy");
						$(this).remove();
					}
				}
			});
			
		});
	});

	return {
		init: function() {
		}
	};
})().init();
